var fs = require('fs');

//异步读取
fs.readFile('../sd.html',function (err,data) {
    if(err){
        throw err;
    }
    else{
        // console.log(data+"");
        //console.log(data.toString())
    }

});

//同步读取
var data = fs.readFileSync('../sd.html');
//console.log(data.toString());


//参数flag 默认是w代表写，先清空再写
fs.writeFile('../wr','test test',function (err) {
    if(err){
        throw err;
    }else{
        console.log('write sucess !')
        //读取写入内容
        fs.readFile('../wr','utf-8',function (err,data) {
            console.log(data.toString());
        })
    }
});

//flag = a 代表追加
fs.writeFile('../wr','test test',{'flag':'a'},function (err) {
    if(err){
        throw err;
    }else{
        console.log('write sucess !')
        //读取写入内容
        fs.readFile('../wr','utf-8',function (err,data) {
            console.log(data.toString());
        })
    }
});




